package com.vr.core.system.dbinfo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vr.mybatis.entity.DbConnInfoEntity;
import com.vr.mybatis.service.DbConnInfoService;
import com.vr.tool.api.R;
import com.vr.tool.util.BaseQuery;
import com.vr.tool.util.SelectConditionUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author kenson
 * @Date 2024/12/2 22:53
 */

@RestController
@RequestMapping("dbManege")
@AllArgsConstructor
public class DbController {

    private final DbConnInfoService dbConnInfoService ;

    @PostMapping("pageList")
    public R<IPage<DbConnInfoEntity>> listPage(@RequestBody BaseQuery<DbConnInfoEntity> query){
        IPage page = dbConnInfoService.page(query.getPage(), SelectConditionUtil.parseWhereSql(query.getConditions()));
        return R.ok(page);
    }

    @PostMapping("save")
    public R<Boolean> save(@RequestBody DbConnInfoEntity dbConnInfoEntity){
        boolean save = dbConnInfoService.save(dbConnInfoEntity);
        return R.ok(save);
    }

    @PostMapping("update")
    public R<Boolean> update(@RequestBody DbConnInfoEntity dbConnInfoEntity){
        boolean save = dbConnInfoService.updateById(dbConnInfoEntity);
        return R.ok(save);
    }

    @PostMapping("delete/{id}")
    public R<Boolean> update(@PathVariable("id") String id){
        boolean save = dbConnInfoService.removeById(id);
        return R.ok(save);
    }

}


